package com.jmb.api.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmb.api.common.result.Result;
import com.jmb.api.model.entity.User;
import com.jmb.api.service.UserService;
import com.jmb.api.vo.user.UserInfoVo;
import com.jmb.api.vo.user.UserUpdateVo;
import com.jmb.api.vo.user.UserVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@Tag(name = "用户管理")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @Operation(summary = "用户管理新增")
    @PostMapping("user/save")
    public Result<UserVo> saveUser(@RequestBody UserVo userVo) {
        userService.createUser(userVo);
        return Result.ok();
    }
    @Operation(summary = "用户管理修改")
    @PostMapping("user/modify")
    public Result<UserVo> modifyUser(@RequestBody UserUpdateVo userUpdateVo) {
        userService.updateUser(userUpdateVo);
        return Result.ok();
    }
    @Operation(summary = "用户管理列表")
    @GetMapping("user/list")
    public Result<IPage<UserInfoVo>> getUserList(@RequestParam Integer pageNum, @RequestParam Integer pageSize,  UserInfoVo userInfo) {
        IPage<UserInfoVo> page = new Page<>(pageNum, pageSize);
        IPage<UserInfoVo> list = userService.getPageUserList(page,userInfo);
        return Result.ok(list);
    }
    @Operation(summary = "用户管理删除")
    @GetMapping("user/remove")
    public Result removeUser(@RequestParam Integer id) {
        userService.removeById(id);
        return Result.ok();
    }
    @Operation(summary = "用户管理重置密码")
    @GetMapping("user/reset")
    public Result resetPassword(@RequestParam Integer id) {
        userService.resetPassword(id);
        return Result.ok();
    }
}
